def max(a): big=a[0] for i in range(len(a)): if(a[i]>big): big=a[i] return(big) a=[4,6,7,90,10,45,67,87,7] print(max(a)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/gg.py ==================== 90
Q2.Program to find cube of a number using function.
def cube(x): return(x*x*x) print(cube(5)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/hh.py ==================== 125
Q3.Program to find mean of list element.
Q4.Program to traverse a string.def mean(a): sum=0 for i in range(len(a)): sum=sum+a[i] mean=sum/len(a) return(mean) a=[1,2,3] print(mean(a)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/gg.py ==================== 2.0
Q5.Program to add two matrix using list.s="my name is xyz" for i in range(len(s)): print(s[i]) Output ==================== RESTART: C:/Users/Dell/Desktop/gg.py ==================== m y n a m e i s x y z
a=[[1,1],[1,1]] b=[[1,1],[1,1]] r=[[0,0],[0,0]] for i in range(len(a)): for j in range(len(a[0])): r[i][j]=a[i][j]+b[i][j] for c in r: print(c) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/gg.py ==================== [2, 2] [2, 2]
0 Comments